package com.cgc.venus.server.ci.controller;

import com.cgc.venus.server.ci.inter.DemoService;
import com.cgc.venus.server.ci.model.entity.Demo;
import com.cgc.venus.server.core.bean.response.VenusResponse;
import com.cgc.venus.server.core.bean.response.VenusResponseStatus;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 业哥 on 2018/5/22.
 */
@Api(value = "demo接口",description="demo接口")
@RequestMapping("/demo-admin")
@RestController
public class DemoController {
    @Autowired
    private DemoService demoService;
    @ApiOperation("demo查询")
    @RequestMapping(value = "/demo", method = RequestMethod.GET)
    @ResponseBody
    public Object demoQuery(@RequestParam("key") String key,@RequestParam("pageNum") Integer pageNum,@RequestParam("rowNum") Integer rowNum) {
        //PageInfo<Demo> pageInfo=demoService.findByKey(key,pageNum,rowNum);
        //VenusResponse<PageInfo<Demo>> response=new VenusResponse<PageInfo<Demo>>(VenusResponseStatus.OK,"",pageInfo);
        VenusResponse<String> response=new VenusResponse<String>(VenusResponseStatus.OK,"","你好12!");
        return  response;
    }

    @ApiOperation(value = "demo新增")
    @RequestMapping(value = "/demo", method = RequestMethod.POST)
    public Object demoAdd(@RequestBody Demo demo)  {
        int row=demoService.insertDemo(demo);
        if(row>0){
            return new VenusResponse<String>(VenusResponseStatus.OK,"新增成功!","");
        }else{
            return new VenusResponse<String>(VenusResponseStatus.VENUS_EXCEPTION,"新增失败!","");
        }
    }

    @ApiOperation("demo修改")
    @RequestMapping(value = "/demo", method = RequestMethod.PATCH)
    @ResponseBody
    public Object demoUpdate(@RequestBody Demo demo) {
        int row=demoService.updateDemo(demo);
        if(row>0){
            return new VenusResponse<String>(VenusResponseStatus.OK,"修改成功!","");
        }else{
            return new VenusResponse<String>(VenusResponseStatus.VENUS_EXCEPTION,"修改失败!","");
        }
    }

    @ApiOperation("demo删除")
    @RequestMapping(value = "/demo", method = RequestMethod.DELETE)
    @ResponseBody
    public Object demoDelete(@RequestParam("id") String id) {
        int row=demoService.deleteDemoById(id);
        if(row>0){
            return new VenusResponse<String>(VenusResponseStatus.OK,"删除成功!","");
        }else{
            return new VenusResponse<String>(VenusResponseStatus.VENUS_EXCEPTION,"删除失败!","");
        }
    }
}